package com.aiyan.edu.govern.gateway;

import com.aiyan.edu.framework.interceptor.FeignClientInterceptor;
import com.aiyan.edu.framework.interceptor.HttpClientInterceptor;
import com.aiyan.edu.govern.gateway.filter.CanaryFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
import reactor.core.publisher.Mono;

/**
 * @author: zqzhou
 * @create: 2019/11/29 16:35
 **/
@SpringBootApplication
public class GovernGatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(GovernGatewayApplication.class, args);
    }

    @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplateBuilder()
                .errorHandler(new DefaultResponseErrorHandler())
                .interceptors(new HttpClientInterceptor())
                .build();

        restTemplate.setRequestFactory(new OkHttp3ClientHttpRequestFactory());

        return restTemplate;
    }

    @Bean
    public FeignClientInterceptor feignClientInterceptor(){
        return new FeignClientInterceptor();
    }
}
